package com.yunquan.ohana.ui.photos.dialog

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.Window
import android.view.WindowManager
import androidx.appcompat.app.AppCompatDialog
import androidx.databinding.DataBindingUtil
import com.yunquan.ohana.R
import com.yunquan.ohana.databinding.DialogCameraTypeBinding

class CameraTypeDialog(context: Context) : AppCompatDialog(context) {
    private lateinit var binding: DialogCameraTypeBinding

    private var onTypeListener: ((Int) -> Unit)? = null

    fun setOnTypeListener(listener: (Int) -> Unit) {
        this.onTypeListener = listener
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_camera_type, null, false)
        setContentView(binding.root)
        val params = window?.attributes
        params?.width = WindowManager.LayoutParams.MATCH_PARENT
        params?.height = WindowManager.LayoutParams.WRAP_CONTENT
        window?.attributes = params
        window?.setGravity(Gravity.BOTTOM)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        initView()
    }

    private fun initView() {
        binding.btnCancel.setOnClickListener { dismiss() }
        binding.btnImage.setOnClickListener {
            onTypeListener?.invoke(1)
            dismiss()
        }
        binding.btnVideo.setOnClickListener {
            onTypeListener?.invoke(2)
            dismiss()
        }
    }

}